package dabs.ginterface;
import dabs.engine.*;

import java.io.*;



public class GameInterface implements Runnable, NotificationHandler {
	private GameEngine geng;
	
	public GameInterface(GameEngine geng) {
		this.geng = geng;
		geng.getPostOffice().registerHandler(this);
	}

	public void handleNotification(Notification notif) {
		System.out.println("Notif received from: " + notif.getSource());
		System.out.println("Contents: " + notif.getDescription());
	}

	public void run() {
		boolean stop = false;
		System.out.println("Starting bunny attack prototype. To start, type help");
		while(!stop) {
			InputStreamReader isr = new InputStreamReader(System.in);
			BufferedReader br = new BufferedReader(isr);
			try {
				String command = br.readLine();
				if (command.equals("quit")) {
					stop = true;
					geng.stop();
				} else if (command.equals("read")) {
					System.out.println(geng.getValue());
				} else if (command.equals("help")) {
					System.out.println("Only two command accepted now are 'quit' and 'read'.\n" +
							"Read will output a number that changes every few seconds\n" +
							"A notification will be generated by\n" +
							"the environment every few seconds");
				} else {
					System.out.println("Command not found: type either quit or read");
				}
			} catch (Exception e) {
				System.out.println("Exception " + e + " caught");
			}
		}
	}
}


